package org.water.common.views;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.JstlView;
/**
 * jar资源 视图
 * @author qzy
 *
 */
public class JarJstlView extends JstlView {

	@Override  
    public boolean checkResource(Locale locale) throws URISyntaxException { 
		
		 String rUrl=getUrl();
		 URL fileUrl=getClass().getResource(rUrl);
		 Boolean flag=false;
		 if(fileUrl!=null){
			 String jarPre="/META-INF/resources";
			 rUrl=rUrl.replaceAll(jarPre, "");
			 flag=true;
			 setUrl(rUrl);
		 }
	     return flag;// 判断该页面是否存在  
    }  
	@Override
	protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		super.renderMergedOutputModel(model, request, response);
		
		/**String rUrl=getUrl();
		InputStream io=getClass().getResourceAsStream(rUrl);
		if(io!=null)
		{
			byte[] buffer = new byte[1024 * 8];
			int count = 0;
			OutputStream os=response.getOutputStream();
			while ((count = io.read(buffer)) != -1) {  
	            os.write(buffer, 0, count);  
	            os.flush();  
	         }  
	         os.close();  
	         io.close(); 
		}
		else
		{
			super.renderMergedOutputModel(model, request, response);
		}**/
	}
}
